package com.sudo.common.component;

import org.springframework.stereotype.Component;
import org.thymeleaf.TemplateEngine;
import org.thymeleaf.context.Context;

import javax.annotation.Resource;

@Component
public class TemplateUtil {

    @Resource
    private TemplateEngine templateEngine;

    public String getTemplate(String template,String div,String css) {
        Context context = new Context();
        context.setVariable("div", div);
        context.setVariable("css", css);
        return templateEngine.process(template,context);
    }

    public String getEmailTemplate(String emailHeader,String emailBody) {
        Context context = new Context();
        String tableInitCss = templateEngine.process("css/tableInit.css", context);
        context.setVariable("tableInitCss", tableInitCss);
        context.setVariable("emailHeader", emailHeader);
        context.setVariable("emailBody", emailBody);
        return templateEngine.process("email.html",context);
    }
}
